﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ToChucHanhChinh.aspx.cs"
    Inherits="Viewer.ToChucHanhChinh.ToChucHanhChinh" %>

<%@ Register Src="UserControl/AddToChucHanhChinh.ascx" TagName="AddToChucHanhChinh" TagPrefix="uc" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../resources/css/main.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        var refreshTree = function(tree, result) {
            var nodes = eval(result);
            if (nodes.length > 0) {
                tree.initChildren(nodes);
            }
            else {
                tree.getRootNode().removeChildren();
            }
        }

        function ConfirmDeleteToChuc(id) {
            Ext.MessageBox.confirm('Thông báo', 'Bạn có chắc chắn xóa record này ko?', function doDel2(btn) {
                if (btn == 'yes') {
                    X.DeleteTochuc(id);
                }
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager Locale="en" ID="ResourceManager1" runat="server"  DirectMethodNamespace="X" >
        <Listeners>
            <BeforeAjaxRequest Handler="Ext.net.Mask.show();" />
            <AjaxRequestComplete Handler="Ext.net.Mask.hide();" />
            <AjaxRequestException Handler="Ext.net.Mask.hide();" />
        </Listeners>
    </ext:ResourceManager>
    <ext:Hidden ID="__CurrentNodeID" runat="server" />
    <ext:Viewport ID="Viewport1" runat="server">
        <Items>
            
            <ext:BorderLayout ID="BorderLayout1" runat="server">
                <West>
                    <ext:TreePanel ID="treeToChucHanhChinh" runat="server" Width="320" Icon="ChartOrganisation"
                        AutoScroll="true" Height="310">
                        <Listeners>
                            <Click Handler="#{__CurrentNodeID}.setValue(node.id);X.LoadGrid(node.id);#{btnAdd}.enable();" />
                        </Listeners>
                        <TopBar>
                            <ext:Toolbar ID="Toolbar1" runat="server">
                                <Items>
                                    <ext:ToolbarTextItem ID="ToolbarTextItem1" runat="server" Text="Tìm kiếm:" />
                                    <ext:ToolbarSpacer />
                                    <ext:TriggerField ID="TriggerField1" runat="server" EnableKeyEvents="true">
                                        <Triggers>
                                            <ext:FieldTrigger Icon="Clear" />
                                        </Triggers>
                                           <%--<Listeners>
                                            <KeyUp Fn="filterTree" Buffer="250" />
                                            <TriggerClick Handler="clearFilter();" />
                                        </Listeners>--%>
                                    </ext:TriggerField>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                    </ext:TreePanel>
                </West>
                <Center>
                    <ext:GridPanel ID="grdToChuc" runat="server" Height="490" AutoExpandColumn="GhiChu"
                        StripeRows="true" MonitorResize="true" AutoWidth="true">
                        <ColumnModel ID="ColumnModel1" runat="server">
                            <Columns>
                                <ext:CommandColumn Width="40" ColumnID="Command" >
                                    <Commands>
                                        <ext:GridCommand>
                                            <Menu>
                                                <Items>
                                                    <ext:MenuCommand Text="Xem chi tiết" CommandName="View" Icon="LayoutHeader" />
                                                    <ext:MenuCommand Text="Sửa " CommandName="Edit" Icon="ApplicationEdit" />
                                                    <ext:MenuCommand Text="Xóa" CommandName="Delete" Icon="Delete" />
                                                </Items>
                                            </Menu>
                                        </ext:GridCommand>
                                    </Commands>
                                </ext:CommandColumn>
                                <ext:Column Header="Tên tổ chức hành chính" DataIndex="TenToChucHanhChinh" Resizable="true" Width="100" />
                                <ext:Column Header="Tổ chức hành chính trực thuộc" DataIndex="TenToChucCha" Resizable="true" Width="150" />
                                <ext:Column Header="Level" DataIndex="ToChucHanhChinhLevel" Resizable="true" />
                                <ext:Column Header="Loại" DataIndex="TenLoaiDonViHanhChinh" Resizable="true" />
                                <ext:Column Header="Ghi chú" DataIndex="GhiChu" Resizable="true" />
                            </Columns>
                        </ColumnModel>
                        <SelectionModel>
                            <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
                        </SelectionModel>
                        <Listeners>
                            <Command Handler="if(command=='View'){X.ShowDialog('View',record.id);}
                                              else if(command=='Edit'){X.ShowDialog('Edit',record.id);}
                                              else if(command=='Delete'){ConfirmDeleteToChuc(record.id);}" />
                        </Listeners>
                        <TopBar>
                            <ext:Toolbar ID="Toolbar" runat="server" LabelAlign="Right">
                                <Items>
                                    <ext:Button ID="btnAdd" runat="server" Text="Tạo mới" IconAlign="Left" Icon="Add" Disabled="true">
                                        <DirectEvents>
                                            <Click OnEvent="btnAddNew_Click">
                                            </Click>
                                        </DirectEvents>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <BottomBar>
                            <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageIndex="1" PageSize="20"
                                HideRefresh="true">
                            </ext:PagingToolbar>
                        </BottomBar>
                        <Store>
                            <ext:Store ID="storeTochucHanhChinh" runat="server">
                                <Reader>
                                    <ext:JsonReader IDProperty="ToChucHanhChinhID">
                                        <Fields>
                                            <ext:RecordField Name="ToChucHanhChinhIDCha" />
                                            <ext:RecordField Name="TenToChucHanhChinh" />
                                            <ext:RecordField Name="ToChucHanhChinhLevel" />
                                            <ext:RecordField Name="GhiChu" />
                                            <ext:RecordField Name="LoaiToChucHanhChinh" />
                                            <ext:RecordField Name="TenLoaiDonViHanhChinh" />
                                            <ext:RecordField Name="TenToChucCha" />
                                        </Fields>
                                    </ext:JsonReader>
                                </Reader>
                            </ext:Store>
                        </Store>
                    </ext:GridPanel>
                </Center>
            </ext:BorderLayout>
        </Items>
    </ext:Viewport>
    <uc:AddToChucHanhChinh ID="winAddToChucHanhChinh" runat="server"></uc:AddToChucHanhChinh>
    </form>
</body>
</html>
